<div class="bina goodsmanager">
    <div class="nav">
        <div class="nav-li focus">商品分销</div>
    </div>
    <hr />

    <div class="infobox">
        <div class="bina_config">
            <h4>商品分销规则</h4>
            {{#if $Cahcs.bina_buff.editing}}
                <label>一级返利： <inputnumber value="{{$Cache.bina_buff.config.first}}" bind-input="{{'$Cache.bina_buff.new_config.first'}}" max="1" min="0" loop="0.01" fixed="2"></inputnumber></label>
                <label>二级返利：<inputnumber value="{{$Cache.bina_buff.config.second}}" bind-input="{{'$Cache.bina_buff.new_config.second'}}" max="1" min="0" loop="0.01" fixed="2"></inputnumber> </label>
                {{#if bus_info.permission.can_bina_to_third}}
                <label>三级返利：<inputnumber value="{{$Cache.bina_buff.config.third}}" bind-input="{{'$Cache.bina_buff.new_config.third'}}" max="1" min="0" loop="0.01" fixed="2"></inputnumber> </label>
                {{/if}}
                <button event-click="{{'$Event.bina_buff.upload'}}">完成</button>
                <button event-click="{{'$Event.bina_buff.cancle'}}">取消</button>
            {{#else}}
                <p>一级返利： {{$Cache.bina_buff.config.first}}</p>
                <p>二级返利： {{$Cache.bina_buff.config.second}}</p>
                {{#if bus_info.permission.can_bina_to_third}}
                <p>三级返利： {{$Cache.bina_buff.config.third||0}}</p>
                {{/if}}
                <button event-click="{{'$Event.bina_buff.edit'}}">修改</button>
            {{/if}}
        </div>
        <br>
        <br>
        <hr>
        <br>
        <div class="bina_list goods_list" style="width:50%;display:inline-block;">
            <h4>分销商品列表：</h4>
            <table>
                <thead>
                    <td class="logo">缩略图</td>
                    <td class="name">名称</td>
                    <td class="method">操作</td>
                </thead>
                {{#each $Cache.bina.bina_list}}
                <tr>
                    <td><img bind-src="{{goods.preview_img_url}}?imageView/1/w/25/h/25" alt="{{goods.goods_name}}的缩略图"></td>
                    <td><a title="{{goods._id}}" href="{{$Top.bus_loginer.url}}/goods-details.html?id={{goods._id}}">{{goods.goods_name}}</a></td>
                    <td>
                        <button event-click="{{'$Top.$Event.cancel_as_bina_goods'}}" >取消使用商品分销</button>
                        {{#if $Private.$Cache.show_setting}}
                        <button event-click="{{'$Top.$Event.close_edit_goods_bina_config'}}" style="font-weight: bold;{{goods.use_custom_bina_id?'background-color:#0058D1;color:#fff;':''}}">✕</button>
                        {{#else}}
                        <button style="{{goods.use_custom_bina_id?'background-color:#0058D1;color:#fff;':''}}" class="icon-numbered-list" event-click="{{'$Top.$Event.open_edit_goods_bina_config'}}"></button>
                        {{/if}}
                    </td>
                </tr>
                {{#> "goods_bina_config","$This",$Private.$Cache.show_setting}}
                {{/each}}
            </table>
        </div>
        <div class="goods_list" style="width:50%;display:inline-block;">
            <h4>商品列表：</h4>
            <table>
                <thead>
                    <td class="logo">缩略图</td>
                    <td class="name">名称</td>
                    <td class="method">操作</td>
                </thead>
                {{#each goods}}
                <tr>
                    <td><img bind-src="{{preview_img_url}}?imageView/1/w/25/h/25" alt="{{goods_name}}的缩略图"></td>
                    <td><a title="{{_id}}" href="{{$Top.bus_loginer.url}}/goods-details.html?id={{_id}}">{{goods_name}}</a></td>
                    <td>
                        {{#if is_bina}}
                        <i>已绑定为分销商品</i>
                        {{#else}}
                        <button event-click="{{'$Top.$Event.set_as_bina_goods'}}" >使用商品分销</button>
                        {{/if}}
                    </td>
                </tr>
                {{/each}}
            </table>

            <pagination
             id="turn-page"
             page-info="$Cache.bus.goods.page_info"
             ></pagination>
        </div>
        <br>
        <br>
        <hr>
        <br>
        <div class="bina_user goods_list">
            <h4>购买分销商品的用户</h4>
            <table>
                <thead>
                    <td>用户名</td>
                    <td>手机号/邮箱</td>
                    <td>支付宝账号</td>
                    <td>一级返利</td>
                    <td>二级返利</td>
                    <td>三级返利</td>
                    <td>已兑现额度</td>
                    <td>可兑现额度</td>
                    <td>操作</td>
                </thead>
                {{#each $Cache.bina.user_list}}
                <tr>
                    <td>{{user.info.name}}</td>
                    <td>{{user.info.mobile_phone||user.info.email}}</td>
                    <td>{{#if user.info.alipay}}{{user.info.alipay}}{{#else}}<i>用户未绑定</i>{{/if}}</td>
                    <td style="text-align:center;">￥{{#Fixed total_first_acc}}</td>
                    <td style="text-align:center;">￥{{#Fixed total_second_acc}}</td>
                    <td style="text-align:center;">￥{{#Fixed total_third_acc}}</td>
                    <td style="text-align:center;">￥{{#Fixed exchange_acc.exchanged_acc}}</td>
                    <td style="text-align:center;">￥{{#Fixed can_apply_acc}}</td>
                    <td>
                        {{#if exchange_acc.state === $Top.config.BINA_STATE.未申请兑换}}
                            <i>用户未申请兑换</i>
                        {{/if}}
                        {{#if exchange_acc.state === $Top.config.BINA_STATE.申请兑换中}}
                            <button event-click="{{'$Top.$Event.bina_申请兑换中_to_商家已付款'}}">商家已打款</button>
                        {{/if}}
                        {{#if exchange_acc.state === $Top.config.BINA_STATE.商家已付款}}
                            <i>等待用户收款</i>
                        {{/if}}
                    </td>
                </tr>
                {{/each}}
            </table>
        </div>
        <br>
        <br>
    </div>
</div>
<xmp type="template" name="goods_bina_config">
    <tr>
        <td><span class="icon-arrow-up "></span></td>
        <td colspan="2" style="text-align: left;">
        <div>
            <android:switch checked="{{goods.use_custom_bina_id}}" bind-input="{{'goods.use_custom_bina_id'}}" event-change="{{'$Top.$Event.use_custom_bina_id.toggle'}}">
            是否使用独立分销规则：<b>{{goods.use_custom_bina_id?'是':'否'}}</b>
        </div>
        {{#if goods.use_custom_bina_id}}
        <div>
            <div>一级返利：<inputnumber value="{{goods_custom_bina_buff.config.first}}" bind-input="{{'goods_custom_bina_buff.config.first'}}" max="1" min="0" loop="0.01" fixed="2" event-input="{{'$Top.$Event.set_custom_bina_config'}}"></inputnumber></div>
            <div>二级返利：<inputnumber value="{{goods_custom_bina_buff.config.second}}" bind-input="{{'goods_custom_bina_buff.config.second'}}" max="1" min="0" loop="0.01" fixed="2" event-input="{{'$Top.$Event.set_custom_bina_config'}}"></inputnumber></div>
            {{#if $Top.bus_info.permission.can_bina_to_third}}
            <div>三级返利：<inputnumber value="{{goods_custom_bina_buff.config.third}}" bind-input="{{'goods_custom_bina_buff.config.third'}}" max="1" min="0" loop="0.01" fixed="2" event-input="{{'$Top.$Event.set_custom_bina_config'}}"></inputnumber></div>
            {{/if}}
        </div>
        {{/if}}
        </td>
    </tr>
    <tr>
        <td colspan="3" style="border:1px #333 solid;border-width:0 1px 1px 1px;"></td>
    </tr>
</xmp>